<?php
// @filename   page_helper.php
// @version    1.0
// @author     洪明伟@shstorm
// @contact    hongmingwei@shstorm.com
// @update     2009-10-16
// @comment    Some Comments

if(!function_exists('page_left')) {
    function page_left() {
        $CI = & get_instance();
        $CI->load->model('Mbank');
        $CI->load->model('Mconfigs');
		$banks = $CI->Mbank->get_bank_list();
		$CI->load->model('Mnews');
		$news_limit = $CI->Mconfigs->get_config_value('index_news_limit');
		$news = $CI->Mnews->get_news_list($news_limit,1,1);
		$CI->template->assign_array(array('banks'=>$banks,'news'=>$news));
    }
}

if(!function_exists('page_common')) {
    function page_common() {
    	page_left();
        page_user();
        page_center();
        page_sidebar_adv();
        $CI = & get_instance();
        $CI->load->model('Mconfigs');
		$config = $CI->Mconfigs->get_site_config();
		$CI->template->assign_array($config);
    }
}

if(!function_exists('page_user')){
    function page_user(){
        $CI = & get_instance();
        $CI->load->library('session');
        $session = $CI->session->userdata('user');
		if ($session['username']) {
			$CI->template->assign('username',$session['username']);
		}
    }
}

if(!function_exists('page_center')){
    function page_center(){
        $CI = & get_instance();
        $CI->load->library('session');
        $session = $CI->session->userdata('user');
		if ($session['username']) {
			$CI->load->model('Mmember');
            $user = $CI->Mmember->get_user_info('username',$session['username']);
            //$discount = $CI->Mmember->get_discount($session['username']);
            $CI->load->model('Mdiscount');
            $order_count = $CI->Mdiscount->get_member_order_count($session['username']);
            $order_discount = $CI->Mdiscount->get_member_discount($session['username']);
            $order_price = $CI->Mdiscount->get_member_order_price($session['username']);
            $order_count = $order_count ? $order_count : '0';
            $order_price = $order_price ? $order_price : '0.00';
            $order_discount = $order_discount ? $order_discount : '0.00';
            /*
            if(empty($discount)){
                $discount = array('price'=>'0.00','discount'=>'0.00');
            }
            if (!$discount['price']){
                $discount['price'] = '0.00';
            }
            if (!$discount['discount']){
                $discount['discount'] = '0.00';
            }
            */
            $discount = array('count'=>$order_count,'discount'=>$order_discount,'price'=>$order_price);
            //print_r($discount);exit;
            $CI->template->assign('user',$user);
            $CI->template->assign('discount',$discount);
		}
    }
}

if(!function_exists('page_sidebar_adv')){
    function page_sidebar_adv(){
        $CI = & get_instance();
        $CI->load->model('Msidebar_area');
        $info = $CI->Msidebar_area->get_info();
        $CI->load->model('Mnews');
        $CI->load->model('Madv');
		$advs = $CI->Madv->get_index_adv();
		$CI->template->assign_array($advs);
		$news = $CI->Mnews->get_news_list($info['news_limit'],1,9);
		$CI->template->assign_array(array('sidebar'=>$info,'side_news'=>$news));
    }
}


?>